package com.manyauthenticationway.server.manyauthenticationway.domain.user

import com.oauth.server.comoauth2server.domain.BaseMongoEntity
import org.springframework.data.mongodb.core.mapping.Document
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.userdetails.UserDetails
import java.io.Serializable

@Document(collection="SysUser")
class SysUser: UserDetails, BaseMongoEntity<SysUser>() {
    private  var username: String? = null
    private  var password: String? = null
    var mobile: String? = null
    var email: String? = null
    var QQ: String? = null
    /**姓名*/
    var fullName: String? = null
    /*是否启用*/
    var isEnabled: Boolean? = null
    /*密码是否未过期*/
    var isCredentialsNonExpired: Boolean? = null
    /*账户是否未过期*/
    var isAccountNonExpired: Boolean? = null
    /*账户没有被锁定*/
    var isAccountNonLocked: Boolean? = null
    /*角色*/
    var authorities: HashSet<SimpleGrantedAuthority>? = null

    override fun getAuthorities() = authorities?: setOf(SimpleGrantedAuthority("ROLE_ADMIN"))

    override fun isEnabled()=this.isEnabled?:true

    override fun getUsername()=this.username?:null

    fun setUsername(username: String){
        this.username = username
    }

    override fun isCredentialsNonExpired()=this.isCredentialsNonExpired?:true

    override fun getPassword()=this.password?:null

    fun setPassword(password: String){
        this.password = password
    }

    override fun isAccountNonExpired()=this.isAccountNonExpired?:true

    override fun isAccountNonLocked()=this.isAccountNonLocked?:true
}